//
//  customerItemViewController.swift
//  account
//
//  Created by Qingke on 16/4/25.
//  Copyright © 2016年 Qingke. All rights reserved.
//

import UIKit

class customerItemViewController: UIViewController {

    
    @IBOutlet weak var textField: UITextField!
    @IBOutlet weak var imageView: UIImageView!
    @IBOutlet weak var saveButton: UIBarButtonItem!
    
    var image = UIImage()
    var item: CustomerLtem?
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    //MARK: - IBaction
    @IBAction func selectImage(sender: UITapGestureRecognizer) {
        print("选择图片")
        let alum = UIImagePickerController()
        alum.sourceType = .PhotoLibrary
        alum.delegate = self
        presentViewController(alum, animated: true, completion: nil)
    
    }
    
    @IBAction func cancelButtonDown(sender: UIBarButtonItem) {
        dismissViewControllerAnimated(true, completion: nil)
    }
    
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
            let name = textField.text
            let image = imageView.image
            item = CustomerLtem(itemName: name ?? "", image: image ?? UIImage(named: "工作")!)
        
    }
    
    
}
extension customerItemViewController:  UIImagePickerControllerDelegate {
    func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage, editingInfo: [String : AnyObject]?) {
        imageView.image = image
        dismissViewControllerAnimated(true, completion: {print("选择图像完毕")})
    }
    
    func imagePickerControllerDidCancel(picker: UIImagePickerController) {
        dismissViewControllerAnimated(true, completion: {print("取消选择图像")})
    }
}
extension customerItemViewController: UINavigationControllerDelegate {
    
}
